package io.renren.modules.lanling.service.impl;

import cn.hutool.core.lang.Validator;
import org.springframework.stereotype.Service;

import java.util.Map;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import io.renren.modules.lanling.dao.AllSubjectDao;
import io.renren.modules.lanling.entity.AllSubjectEntity;
import io.renren.modules.lanling.service.AllSubjectService;


@Service("allSubjectService")
public class AllSubjectServiceImpl extends ServiceImpl<AllSubjectDao, AllSubjectEntity> implements AllSubjectService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        EntityWrapper<AllSubjectEntity> entityEntityWrapper = new EntityWrapper<>();
        Object typeId = params.get("typeId");
        if (Validator.isNotEmpty(typeId)) {
            entityEntityWrapper.eq("type_id", typeId);
        }

        Object name = params.get("name");
        if (Validator.isNotEmpty(name)) {
            entityEntityWrapper.like("subject_name", name.toString());
        }

        Page<AllSubjectEntity> page = this.selectPage(
                new Query<AllSubjectEntity>(params).getPage(), entityEntityWrapper);

        return new PageUtils(page);
    }

}
